@extends('layouts.layouts')
@section('title')
    <title>后台首页</title>
    <style>
        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }
        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }
        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }
    </style>
@endsection
@section('content')
<script src="/js/upload.js" type="text/javascript"></script>
    <div class="modal small fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h3 id="myModalLabel">Delete Confirmation</h3>
                </div>
                <div class="modal-body">
                    <p class="error-text"><i class="fa fa-warning modal-icon"></i>Are you sure you want to delete the user?<br>This cannot be undone.</p>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>
                    <button class="btn btn-danger" data-dismiss="modal">Delete</button>
                </div>
            </div>
        </div>
    </div>
    <div class="content">
        <div class="header">
            <h1 class="page-title">pt后台管理</h1>
            <ul class="breadcrumb">
                <li><a href="/tags/list">标签列表</a> </li>
                <li class="active">编辑标签</li>
            </ul>
        </div>
        <div class="main-content">
            <ul class="nav nav-tabs">
              <li class="active"><a href="#home" data-toggle="tab">信息</a></li>
              <!-- <li><a href="#profile" data-toggle="tab">Password</a></li> -->
            </ul>

          <div class="row">
            <div class="col-md-4">
              <br>
              <div id="myTabContent" class="tab-content">
                <div class="tab-pane active in" id="home">
                <form id="tab2" action="/tags/uptag" method="post">
                      <div class="form-group">
                            <label>seo标题</label>
                            <input type="text" value="{{$tag['seo_title']}}" name="seo_title" class="form-control">
                      </div>
                      <div class="form-group">
                            <label>seo描述</label>
                            <input type="text" value="{{$tag['seo_description']}}" name="seo_description" class="form-control">
                      </div>
                      <div class="form-group js-reset-image">
                        <a href="javascript:;" class="file">上传封面图
                            <input type="file" class="upload_img cover" name="coverUrl" placeholder="封面图">
                        </a>
                        <img src="{{env('IMG_URL')}}{{$tag['cover_url']}}" style="width:50%;margin-left: 10px;" id="banner_url" />
                        <span id="error"></span>
                      </div>
                      <div class="form-group">
                      <label>标签名称</label>
                      <input type="text" value="{{$tag['title']}}" name="title" class="form-control">
                      </div>
                      <div class="form-group">
                      <label>标签类别</label>
                      <select class="form-control" name="type">
                          <option value="{{$tag['type']}}">{{App\Contant\CommonType::trans($tag['type'])}}</option>
                          <option value="COURSE">{{App\Contant\CommonType::COURSE}}</option>
                          <option value="ARTICLE">{{App\Contant\CommonType::ARTICLE}}</option>
                          <option value="CIRCLE">{{App\Contant\CommonType::CIRCLE}}</option>
                        </select>
                      </div>
                        <div class="form-group">
                        <label>标签状态</label>
                        @if($tag['state']==1)
                          <label class="checkbox-inline">
                            <input type="radio" id="inlineCheckbox1" value="1" name="state" checked="true"> 上线
                          </label>
                          <label class="checkbox-inline">
                            <input type="radio" id="inlineCheckbox2" value="0" name="state"> 禁用
                          </label>
                        @else
                          <label class="checkbox-inline">
                            <input type="radio" id="inlineCheckbox1" value="1" name="state"> 上线
                          </label>
                          <label class="checkbox-inline">
                            <input type="radio" id="inlineCheckbox2" value="0" name="state" checked="true"> 禁用
                          </label>
                         @endif   
                        </div>
                        

                        <!-- <div class="form-group">
                          <label>Address</label>
                          <textarea value="Smith" rows="3" class="form-control">2817 S 49th
                              Apt 314
                              San Jose, CA 95101
                          </textarea>
                        </div> -->
                    <br/>
                    <div class="form-group">
                      {{csrf_field()}}
                      <input type="hidden" name="cover_url" id="input_banner_url" />
                      <input type='hidden' name="id" value="{{$tag['id']}}" />
                      <button type="button" class="btn btn-primary" id="submit_form_add">提交</button>
                    </div>
                  </form>
                </div>
              </div>
            </div>
          </div>    
        </div>
    </div>

    
    <script type="text/javascript">
        var imgUrl = '{{env('IMG_URL')}}'; 
        $(document).ready(function(){
            //提交信息
            $("#submit_form_add").click(function(){
                var data = $("#tab2").serialize();
                data = decodeURIComponent(data,true);
                $.ajax({
                    type:"POST",
                    url:"/tags/uptag",
                    data:data,
                    dataType:'json',
                    success:function(result){
//                        console.log(result);
                        if(result.code==1){
                            window.location.href='/tags/list';
//                            location.reload();
                        }else{
                            swal(result.msg);
                        }
                    }
                });
            });

            $(".alert_form_edit-").click(function(){
                var id = $(this).attr("data-id");
                var title = $(this).attr("data-title");
                var type  = $(this).attr("data-type");
                var state = $(this).attr("data-state");
                alert(id);
                alert(title);
                alert(type);
                alert(state);
            });

            $("#submit_form_edit-").click(function(){
                var data1 = $("#tag_form_edit").serialize();
                data1 = decodeURIComponent(data1,true);
                $.ajax({
                    type:"POST",
                    url:"/tags/addtag",
                    data:data1,
                    dataType:'json',
                    success:function(result){
                        console.log(result);
                        if(result.code==1){
                            location.reload();
                        }else{
                            swal(result.msg);
                        }
                    }
                });
            });

            $(".upload_img").UploadImg({
                url : '/course/fileUpload',
                quality : '0.8', //压缩率，默认值为0.8
                // 如果quality是1 宽和高都未设定 则上传原图
                mixsize : '10000000',
                //type : 'image/png,image/jpg,image/jpeg,image/pjpeg,image/gif,image/bmp,image/x-png',
                before : function(blob,className){
                //var className = '#'+className;
                //$(className).attr('src',blob);
                },
                error : function(res){
                    $('#img').attr('src','');
                    $('#error').html(res);
                },
                success : function(url,className){
                    console.log(url);
                    $('#banner_url').attr('src', imgUrl + url);
                    $('#input_banner_url').val( url);
                }
            });       

        })
    </script>
@endsection